home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Disc to the Future 2
/
Disc to the Future Part II Programmer's Reference (Wayzata Technology)(6013)(1992).bin
/
MAC
/
THINKC
/
4_0
/
VANTAGE_
/
VFIL_SKE.C
< prev
Wrap
C/C++ Source or Header
|
1989-09-15
|
8KB
|
297 lines
/**************************************************************/
/* This is a sample Vantage VFIL written in LightSpeed C V4.0.
It pretends to support Microsoft Word V4.0 files, but it's
only a skeleton - no conversion is actually performed. (Sorry,
but I'm not permitted to disclose the format of a Word file.)
It's purpose is only to show the structure of a Vantage VFIL.
Feel free to use it, abuse it, or distribute it as you see fit.
To build the VCMD resource, set the following project types:
Code Resource
File Type = VEXT
Creator = VEXI
Custom Header = ON (checked)
Type = VFIL
ID = 1 (arbitrary)
Attrs = 00
Also include the MacTraps library and check the
MacHeaders option in the code generation options dialog.
Dave McWherter, 9/15/89
Signature Software
215-639-8764
*/
/**************************************************************/
#include <MacTypes.h>
/**************************************************************/
/* Data type aliases: */
#ifndef bool
#define bool int
#endif
#ifndef uchar
#define uchar unsigned char
#endif
/****************************************************************/
/* Status codes for Vantage: */
#define OK 0
#define ERR -1
/****************************************************************/
/* Prototypes for our routines: */
void header(void);
void main(void);
pascal int open_close(char **errmsg);
pascal int convert(Handle olddata, long oldlength, long creator, char *filename,
int vrefnum, Handle *newdata, long *newlength, char **errmsg);
uchar getbyte(void);
unsigned int getword(void);
unsigned long getlong(void);
void return_errmsg(char *msg, char **msgptr);
/****************************************************************/
/* Our custom code header used by Vantage to call the VCMD.
Several things to note here:
1.) Be very careful of the alignment forced by the dc.b statement.
LSC aligns each dc.b. I don't know of any other way in LSC to
generate these Pascal strings needed in the Vantage header, which
means every time you change the strings, you have to hand-count
the bytes, change the size bytes, adjust the pad bytes, and worry
about alignment.
2.) LSC can only generate PC-relative offsets in the dc.w statement.
Since Vantage wants header-relative offsets for each of the entry
points, we have to correct the offsets generated by the LSC assembler
in the header by +2 for Close, and +4 for Convert.
3.) Since we're using a custom header, we have to load A0 ourselves
on entry to each routine. (Actually, we only need A0 setup so that
RememberA0() works, and we only need RememberA0 if we need globals.
Only our Execute routine needs globals (implicitly for the error
strings), so we really only need the A0 setup and SetUpA4() and
RestoreA4() stuff in the Execute routine. But I put it all in
every routine just for consistency's sake.)
*/
void header()
{
asm {
dc.w @1+0 ; Offset to Open routine
dc.w @2+2 ; Offset to Close routine
dc.w @3+4 ; Offset to Convert routine
dc.l 'WDBN' ; File type we handle
; The prompt displayed during file conversion by Vantage...
dc.b 15, 'W', 'o', 'r', 'd', ' ', '4', '.', '0', ' ', 'V', 'F', 'I', 'L', '.', ' '
; The VFIL's name in the installer...
dc.b 13, 'W', 'o', 'r', 'd', ' ', '4', '.', '0', ' ', 'V', 'F', 'I', 'L'
; *** Special note: Vantage V1.0 and 1.1 have a problem displaying the text of the
; *** prompt. Only an empty dialog is displayed. Vantage V2.0 fixes this, but you
; *** might not want to use a prompt because of this. Or, you could enable or disable
; *** the prompt by changing your header dynamically depending on the Vantage version.
@1: lea header,a0 ; We must load A0 ourselves so RememberA0() works
jmp open_close
@2: lea header,a0
jmp open_close
@3: lea header,a0
jmp convert
}
}
/**************************************************************/
/* Include LSC's magical A0 and A4 stuff... */
/* This must be somewhere _after_ the header() function. */
static __GetA4(void);
void SetUpA4(void);
#include <SetupA4.h>
/****************************************************************/
void main()
{
/* We don't use a main() */
}
/****************************************************************/
/* Called once when Vantage is opened. Use it to do any necessary
setup. If you return an error code, then your VFIL resource is
dumped and won't be called again.
*** Since we don't need any special open or close processing,
our open and close routines can be the same. */
pascal int open_close(errmsg)
char **errmsg;
{
/* We don't need any open or close processing
RememberA0();
SetUpA4();
do_open_or_close_stuff();
RestoreA4();
*/
return OK;
}
/****************************************************************/
/* Globals: */
char *rdata; /* raw file data read by Vantage and passed to us */
long roff; /* current offset into above */
bool error; /* TRUE if any error occurred */
/****************************************************************/
/* This is our Convert routine that extracts the text from the file
and returns it to Vantage. */
pascal int convert(olddata, oldlength, creator, filename, vrefnum, newdata, newlength, errmsg)
Handle olddata;
long oldlength;
long creator;
char *filename;
int vrefnum;
Handle *newdata;
long *newlength;
char **errmsg;
{
long textsize;
Handle texthdl;
uchar *text, c;
long *ticks;
RememberA0();
SetUpA4();
*newdata = *newlength = 0;
texthdl = 0;
error = FALSE;
rdata = *olddata; /* make raw data ptr global so subroutines can get at it */
/* Do your conversion here. Get yourself a handle for the converted
text into 'texthdl' and stuff the converted text into it. Use
getbyte(), getword(), and getlong() to read data from the raw file
data, and control the read position by setting 'roff' to where you
want to read from. Put the size of the converted text into 'textsize'. */
/* Special note: If your VFIL supports a file type that Vantage already supports
internally, then your VFIL replaces Vantage's internal code for handling all
files of that type. This means that your VFIL should not only support newer
file formats for that type than Vantage does, but it also must support the old
formats too. For example, the real Word 4.0 VFIL also provides support for
Word 3.0 files, because Vantage gives all files of type WDBN to the VFIL,
whether Vantage could internally support them or not. */
if ((texthdl && !error)) {
HUnlock(texthdl);
*newdata = texthdl; /* Pass the converted text back to Vantage */
*newlength = textsize;
/* Delay(60, &ticks); */ /* Prompt delay so they can see it (if you use a prompt) */
RestoreA4();
return OK;
}
else {
if (texthdl)
DisposHandle(texthdl);
RestoreA4();
return ERR;
}
}
/****************************************************************/
/* Get a byte from raw file data starting at roff and bump roff by 1. */
uchar getbyte()
{
return rdata[roff++];
}
/****************************************************************/
/* Get a word from raw file data starting at roff and bump roff by 2. */
unsigned int getword()
{
unsigned int res;
res = getbyte() << 8;
res |= getbyte();
return res;
}
/****************************************************************/
/* Get a long from raw file data starting at roff and bump roff by 4. */
unsigned long getlong()
{
unsigned long res;
res = getword() << 16;
res |= getword();
return res;
}
/****************************************************************/
/* Returns a pointer to an error message to Vantage. */
void return_errmsg(msg, msgptr)
char *msg;
char **msgptr;
{
*msgptr = msg;
error = TRUE;
}
/****************************************************************/